<template>
  <view class="goods-list">
    <view class="item" v-for="item in list" :key="item.goods_id">
      <image mode="aspectFill" :src="item.goods_small_logo" class="poster" />
      <view class="name">{{ item.goods_name }}</view>
      <view class="info">
        <view class="sale-price">{{ item.goods_price }}</view>
        <!-- <view class="line-price">原价￥{{ item.prcs }}</view> -->
        <view class="btn" @click="handelAddCart(item)">加入购物车</view>
      </view>
    </view>
  </view>
</template>

<script>
import { mapState, mapMutations, mapGetters } from "vuex";
export default {
  data() {
    return {
     list: [
				{
					goods_id: 1,
					goods_name: "商品",
					goods_price: "99",
					goods_count: 0,
					goods_small_logo:
						"https://img0.baidu.com/it/u=1306953993,1077003894&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1703869200&t=14b9fadcd5dd19654036516ab0ae48b3",
					goods_state: false,
				},
				{
					goods_id: 2,
					goods_name: "商品1",
					goods_price: "69",
					goods_count: 0,
					goods_small_logo:
						"https://img0.baidu.com/it/u=1306953993,1077003894&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1703869200&t=14b9fadcd5dd19654036516ab0ae48b3",
					goods_state: false,
				},
				{
					goods_id: 3,
					goods_name: "商品2",
					goods_price: "99",
					goods_count: 0,
					goods_small_logo:
						"https://img0.baidu.com/it/u=1306953993,1077003894&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1703869200&t=14b9fadcd5dd19654036516ab0ae48b3",
					goods_state: false,
				},
				{
					goods_id: 4,
					goods_name: "商品3",
					goods_price: "89",
					goods_count: 0,
					goods_small_logo:
						"https://img0.baidu.com/it/u=1306953993,1077003894&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1703869200&t=14b9fadcd5dd19654036516ab0ae48b3",
					goods_state: false,
				},
			],
    };
  },
  computed: {
    /* 计算左侧滚动位置定位 */
    ...mapGetters("m_cart", ["total", "totalPrice"]),
    ...mapState("m_cart", ["cart"]),
  },
  methods: {
    ...mapMutations("m_cart", ["addToCart", "clearCart"]),
    handelAddCart(item) {
      this.addToCart(item);
    },
  },
};
</script>

<style lang="scss" scoped>
.goods-list {
  padding: 32rpx;

  .item {
    margin-bottom: 68rpx;

    .poster {
      width: 100%;
      height: 686rpx;
      background: #fcfcfc;
    }

    .name {
      font-weight: 500;
      font-size: 32rpx;
      line-height: 48rpx;
      margin-top: 32rpx;
    }

    .info {
      display: flex;
      align-items: center;
      margin-top: 36rpx;

      .sale-price {
        font-size: 48rpx;
        font-weight: 600;

        &::before {
          content: "￥";
          font-size: 24rpx;
          margin-right: 4rpx;
        }
      }

      .line-price {
        font-size: 24rpx;
        color: #aaaaaa;
        margin-left: 12rpx;
        text-decoration: line-through;
      }

      .btn {
        font-size: 32rpx;
        font-weight: 500;
        padding: 0 48rpx;
        height: 72rpx;
        background: linear-gradient(48deg, #48f9b2 0%, #29dfff 100%);
        border-radius: 40rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        margin-left: auto;
      }
    }
  }
}
</style>